package org.cx.web;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Login extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * 初始化方法
	 */
	public void init(ServletConfig config) throws ServletException {
		System.out.println("初始化");
	}

	/**
	 * @see Servlet#destroy()
	 */
	public void destroy() {
		System.out.println("销毁");
	}

	/**
	 * 不写doget和dopost方法时，两种请求均提交到service方法,doget、dopost不会和service同时出现
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userName = request.getParameter("userName");
		String password = request.getParameter("password");
		String sex = request.getParameter("sex");
		String city = request.getParameter("city");
		String[] books = request.getParameterValues("book");
		
		
		
		System.out.println(userName);
		System.out.println(password);
		System.out.println(sex);
		System.out.println(city);
		
		if (books != null) {
			for (String book : books) {
				System.out.println(book);
			}
		}
		
		request.getSession().setAttribute("userName", userName);
		
		response.getWriter().print(userName+"密码"+password);
	}

	/**
	 * get请求将会提交至doget方法这里
	 */
//	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//	}

	/**
	 * post请求提交至dopost处理
	 */
//	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//	}

}
